package com.seecen.controller;


import com.seecen.pojo.entity.User;
import com.seecen.service.CheckinService;
import com.seecen.service.UserService;
import com.seecen.utils.FileUploadUtil;
import com.seecen.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private CheckinService checkinService;

    @PostMapping("login")
    public Result login(@RequestBody User user) {
        Result ret = userService.login(user);
        log.info("ret ====> {}", ret);
        return ret;
    }

    @GetMapping("getUser")
    public Result getUser(@RequestHeader String token) {
        Result ret = userService.getUser(token);
        log.info("ret ====> {}", ret);
        return ret;
    }

    @GetMapping("getUserStats")
    public Result getUserStats(@RequestHeader String token) {
        Result ret = userService.getUserStats(token);
        log.info("getUserStats ret ====> {}", ret);
        return ret;
    }

    @PostMapping("register")
    public Result register(@RequestBody User user) {
        // 记录注册请求中的头像信息
        log.info("用户注册请求 - 用户名: {}, 头像URL: '{}'",
                user.getUsername(),
                user.getAvatar() != null ? user.getAvatar() : "无");

        Result ret = userService.register(user);
        log.info("ret ====> {}", ret);
        return ret;
    }

    @PutMapping("resetAccount")
    public Result resetAccount(@RequestBody User user) {
        Result ret = userService.resetAccount(user);
        log.info("ret ====> {}", ret);
        return ret;
    }

    // 打卡
    @PostMapping("checkin")
    public Result checkin(@RequestHeader String token) {
        Result ret = checkinService.checkin(token);
        log.info("checkin ret ====> {}", ret);
        return ret;
    }

    @PutMapping("updateUser")
    public Result updateUser(@RequestHeader String token, @RequestBody User user) {
        Result ret = userService.updateUser(token, user);
        log.info("updateUser ret ====> {}", ret);
        return ret;
    }
    // 注销
    @DeleteMapping("revokeAccount")
    public Result revokeAccount(@RequestHeader String token) {
        Result ret = userService.revokeAccount(token);
        log.info("revokeAccount ret ====> {}", ret);
        return ret;
    }
}
